<?php namespace simpleFlow;

use simpleFlow\Object as SFObject;

/**
 * Manage user session
 * @package simpleFlow
 * @author Guilherme Fontenele
  */
class Session extends SFObject
{
	/**
	 * Initialize the class
	 */
	public static function init()
	{
		session_start();
	}
	
	/**
	 * Setters
	 * @method __set
	 * @param string $var Name of attribute
	 * @param id $params Parameter of any type
	 */
	public function __set($var,$params)
	{
		$_SESSION[$var] = $params;
	}
	
	/**
	 * Getters
	 * @method __get
	 * @param string $var Name of attribute
	 * @return id Parameter
	 */
	public function __get($var)
	{
		return isset($_SESSION[$var]) ? $_SESSION[$var] : false;
	}
	
	/**
	 * Add parameter
	 * @param string $var Name of attribute
	 * @param id $param Parameter
	 */
	public static function addParam($var,$param)
	{
		$_SESSION[$var] = $param;
	}
	
	/**
	 * Get parameter
	 * @param string $var Name of attribute
	 * @param boolean $clear Clean the attribute in session
	 * @return id Parameter
	 */
	public static function getParam($var,$clear = false)
	{
		if(isset($_SESSION[$var]))
		{
			$_tmp = $_SESSION[$var];
			if($clear) { unset($_SESSION[$var]); }
			return $_tmp;
		}else{
			return false;
		}
	}
	
	/**
	 * Verify if have an attribute
	 * @param string $var Name of attribute
	 * @return boolean If have the attribute
	 */
	public function hasParam($var)
	{
		return isset($_SESSION[$var]);
	}
	
	/**
	 * Destroy the session
	 */
	public static function destroy()
	{
		session_destroy();
	}
}

?>